package xuhaijia.lanou3g.autohome.findcar.screen;
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                   \\`.
//        .'//            为什么坚持  想一想当初             \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-.  \\`.
//    .'//.-"                 `-.  |  .-'                 "-. \\`.
//  .'//______.============-..   \ | /   ..-============._______\\`.
//.'//____________________________\|/_____________________________\\`.
// 
//                             

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spannable;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import xuhaijia.lanou3g.autohome.R;

/**
 * Created by 7 on 16/8/31.
 */
public class ScreenInAdapter extends RecyclerView.Adapter<ScreenInAdapter.ScreenInViewHolder>{
    Context context;
    ScreenInBean screenInBean;

    public ScreenInAdapter(Context context) {
        this.context = context;
    }

    public void setScreenInBean(ScreenInBean screenInBean) {
        this.screenInBean = screenInBean;
        notifyDataSetChanged();
    }

    @Override
    public ScreenInViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_screenin , parent , false);
        ScreenInViewHolder screenInViewHolder = new ScreenInViewHolder(view);
        return screenInViewHolder;
    }

    @Override
    public void onBindViewHolder(ScreenInViewHolder holder, int position) {
        holder.type.setText(screenInBean.getResult().getTabinfos().get(position).getTabtitle());
        String text = screenInBean.getResult().getTabinfos().get(position).getTabsubtitle();
        Spanned spanned = Html.fromHtml(text);
        holder.count.setText(spanned);
    }

    @Override
    public int getItemCount() {
        if (screenInBean.getResult().getTabinfos() == null) {
            return 0;
        }
        return screenInBean.getResult().getTabinfos().size();
    }

    public class ScreenInViewHolder extends RecyclerView.ViewHolder {
        TextView type;
        TextView count;
        public ScreenInViewHolder(View itemView) {
            super(itemView);
            type = (TextView) itemView.findViewById(R.id.item_screenin_type);
            count = (TextView) itemView.findViewById(R.id.item_screenin_count);
        }
    }
}
